package com.lanou.myim.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lanou.myim.R;
import com.lanou.myim.presenter.AddFriendsPresenter;
import com.lanou.myim.presenter.AddFriendsPresenterInterface;
import com.lanou.myim.tools.ParseSingleton;


/**
 * Created by dllo on 16/3/3.
 */
public class AddFriendsActivity extends BaseActivity implements View.OnClickListener,AddFriendsActivityInterface {
    private View addFriendLayout;
    private Button serachBtn;
    private Button addBtn;
    private EditText searchEt;
    private ImageView pictureIv;
    private TextView userNameIv;

    private AddFriendsPresenterInterface presenterInterface;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_friends);
        addFriendLayout = findViewById(R.id.layout_add_friend);
        serachBtn = (Button) findViewById(R.id.btn_search);
        addBtn = (Button) findViewById(R.id.btn_add_friend);
        searchEt = (EditText) findViewById(R.id.et_search);
        pictureIv = (ImageView) findViewById(R.id.iv_picture_search);
        userNameIv = (TextView) findViewById(R.id.tv_user_name_searched);
        serachBtn.setOnClickListener(this);
        addBtn.setOnClickListener(this);
        addFriendLayout.setVisibility(View.GONE);

        presenterInterface = new AddFriendsPresenter(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_search:
                presenterInterface.searchFriend(searchEt.getText().toString());
                break;
            case R.id.btn_add_friend:
                presenterInterface.addFriend(userNameIv.getText().toString());
                break;
        }
    }

    @Override
    public void showLayout(String name) {
        addFriendLayout.setVisibility(View.VISIBLE);
        userNameIv.setText(name);
        ParseSingleton.setBitmap(name,pictureIv);
    }

    @Override
    public void dismissLayout() {
        addFriendLayout.setVisibility(View.GONE);
    }
}
